package com.shg.web.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shg.bean.Users;
import com.shg.service.UsersService;
import com.shg.web.tools.WebTool;

@Controller
public class BasicAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Resource UsersService usersService;
	
	private Users user;
	
	private String message;
	
	public String top(){
		user = WebTool.getLogin();
		return "top";
	}

	public String login(){
		try {
			user = usersService.getLogin(user.getUserEmail(), user.getPassWord());
		} catch (Exception e) {
			e.printStackTrace();
			this.message="操作发生异常";
			return "error";
		}
		if(user!=null)
			WebTool.saveUser(user);
		else
			message="用户名或者密码有误";
		return "top";
	}
	/**
	 * 退出登录
	 * @return
	 */
	public String loginOut(){
		user = WebTool.setLoginOut();
		return "top";
	}
	/**
	 * 用户注册
	 * @return
	 */
	public String register(){
		return "register";
	}
	/**
	 * Json
	 * @return
	 */
	public String json(){
		return "json";
	}
	/**
	 * 客服中心
	 * @return
	 */
	public String service(){
		return "service";
	}
	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}


}
